﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.Model;
using Gift.DAL;
using Gift.WebApp;
using System.Data;
using Gift.Model.ENUM;

namespace WebSite.admin.order
{
    public partial class orderComplainList : BaseAdmin
    {
      

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                base.ValidateLoginRule(ERule.OrderComplain);
                this.BindCompainTypeList();
                this.BindComainList();
            }
        }

        void BindCompainTypeList()
        {
            DataSet ds;
            ds = BaseFactory.theCompain.GetList("");
            if (ds != null && ds.Tables.Count > 0)
            {
                this.ddlCompainType.DataTextField = "CompainName";
                this.ddlCompainType.DataValueField = "CompainId";
                this.ddlCompainType.DataSource = ds.Tables[0].DefaultView;
                this.ddlCompainType.DataBind();
                this.ddlCompainType.Items.Insert(0,new ListItem("投诉类别...", "0"));
            }
        }

        void BindComainList()
        {
            DataSet ds;
            ds = BaseFactory.theOrderCompain.GetOrderCompainList(long.Parse(ordercode.Value.Trim() == "" ? "0" : ordercode.Value.Trim()), int.Parse(this.ddlCompainType.SelectedItem.Value), int.Parse(this.ddlProcessType.SelectedItem.Value), int.Parse(base.Administrator.CompanyId));
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                this.GridView1.DataSource = dt.DefaultView;
                this.GridView1.DataBind();


                this.LblCurrentIndex.Text = "当前第 " + ((this.GridView1.PageIndex + 1)).ToString() + "页";
                this.LblPageCount.Text = "共 " + this.GridView1.PageCount.ToString() + "页";
                this.LblRecordCount.Text = "总计 " + dt.Rows.Count.ToString() + "个记录";
                if (dt.Rows.Count == 0)
                {
                    this.btnFirst.Visible = false;
                    this.btnPrev.Visible = false;
                    this.btnNext.Visible = false;
                    this.btnLast.Visible = false;
                    this.LblCurrentIndex.Visible = false;
                    this.LblPageCount.Visible = false;
                    this.LblRecordCount.Visible = false;
                }
                else if (this.GridView1.PageCount == 1)
                {
                    this.btnFirst.Visible = false;
                    this.btnPrev.Visible = false;
                    this.btnNext.Visible = false;
                    this.btnLast.Visible = false;
                }
                this.btnFirst.CommandName = "1";
                this.btnPrev.CommandName = (this.GridView1.PageIndex == 0) ? "1" : this.GridView1.PageIndex.ToString();
                this.btnNext.CommandName = (this.GridView1.PageCount == 1) ? this.GridView1.PageCount.ToString() : ((this.GridView1.PageIndex + 2)).ToString();
                this.btnLast.CommandName = this.GridView1.PageCount.ToString();
                this.ddlCurrentPage.Items.Clear();
                if (this.GridView1.PageCount > 0)
                {
                    for (int i = 1; i <= this.GridView1.PageCount; i++)
                    {
                        this.ddlCurrentPage.Items.Add(i.ToString());
                    }
                    this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
                }
            }
        }

        protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
        {
            this.BindComainList();
        }

        protected void PagerButtonClick(object sender, EventArgs e)
        {
            this.GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandName) - 1;
            this.BindComainList();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
            this.BindComainList();
        }
    }
}